#include "../SocketCommon/common.h"
#pragma comment(lib,"../Debug/SocketCommon.lib")
#pragma comment(lib,"WS2_32.lib")

int main()
{
	SOCKET client;
	struct sockaddr_in sa;
	char buf[4];
	int len;
	int ir;

	init();

	client = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	if(client==INVALID_SOCKET){
		ERROR_EXIT("socket");
	}

	bzero(&sa,sizeof(sa));
	inet_pton(AF_INET,"127.0.0.1",&(sa.sin_addr));
	sa.sin_family = AF_INET;
	sa.sin_port = htons(1234);

	ir = connect(client,(const struct sockaddr*)&sa,sizeof(sa));
	if(ir<0){
		ERROR_EXIT("connect");
	}

	for(;;){
		bzero(buf,4);
		len = recv(client,buf,3,0);
		if(len>0){
			printf("%s",buf);
		}
		else if(len<0){
			ERROR_EXIT("recv");
		}
		else{
			break;
		}
	}
	printf("\n");

	closesocket(client);

	fin();
	system("PAUSE");
	return 0;
}
